home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Singles Flirt Up Your Life! (German)
/
Singles Flirt Up Your Life.iso
/
data1.cab
/
Statemachine
/
playByTableChar.lua
< prev
next >
Wrap
Text File
|
2004-01-29
|
12KB
|
444 lines
beginStateMachine()
onEnter(function(msg)
print("play by table character state machine onEnter ");
local chair = retrieveStateObject("chair");
if (not chair) then
print("playByTableChar::onEnter: no chair");
end
--storeStateObject("chair", chair);
if (chair) then
--chair does exist
if (getParent().isOneActionPointLocked(chair)) then
-- action point is locked
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
else
getParent().lockActionPoints(chair);
-- check wich side of chair
local actionPointName = retrieveData("chairActionPointName");
print("Play by table actionPointName" .. actionPointName);
if (actionPointName == "sit2") then
storeData("mirrorAnims", true);
else
storeData("mirrorAnims", false);
end
end
else
-- chair does not exist anymore
getParent().setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendMsg("emoThink", getParent().walkSO);
exitStateMachine();
end
end )
onExit(function(msg)
-- local chair = retrieveStateObject("chair");
-- if (chair) then
-- getParent().unlockActionPoints(chair);
-- getParent().stopAllActivities(boardgame);
-- removeStateObject("chair");
-- end;
local partner = retrieveStateObject("partner");
if (partner) then
getParent().unlockActionPoints(partner.getParent());
getParent().stopAllActivities(partner.getParent());
removeStateObject("partner");
end;
-- removeStateObject("table");
-- removeStateObject("boardgame");
unlockAll("chair");
unlockAll("table");
unlockAll("boardgame");
end )
-- sit down on chair
state("sitDownWithGame")
onEnter(function(msg)
print("sitDownWithGame onEnter");
local chair = retrieveStateObject("chair");
if (not chair) then
print("eatByTableChar::sitDown::onEnter: no chair");
end
setPose("sitdownChair", retrieveData("mirrorAnims"));
chair.startAnimation("ChairSitdown");
chair.playSound("Stuhl hinsetzen");
-- send a delayed message for sit sound
sendDelayedMsgThis("sitSound", 2500);
-- local boardgame = retrieveStateObject("boardgame");
--
-- if (not boardgame) then
-- print("playByTableChar::sitDown::onEnter: no boardgame box");
-- else
-- getParent().detachRightObjectHolder();
-- getParent().detachLeftObjectHolder();
-- boardgame.deleteGameObject();
-- end
freeHands(getParent());
print("create opened game");
local boardgame = getParent().loadGameObject("StandardGO","boardgame");
storeStateObject("boardgame", boardgame);
local table = retrieveStateObject("table");
local tableActionPointName = retrieveData("tableActionPointName");
local tableHeight = table.getTableHeight();
print("tableHeight: " .. tableHeight);
local tablePos = boardgame.tableYPosition;
if (not tablePos) then print("WARNING no attribute -tableYPosition- found"); tablePos = 0; end;
table.addObjectToActionPoint(boardgame, tableActionPointName, 0, tablePos, tableHeight);
-- we need free hands for playing
local hands = getParent().handSO;
if (not hands) then
print("no hands found");
else
hands.stopPose();
end
storeData("activePart", true);
end )
onMsg("queue", function(msg)
setState("standUp");
end )
onMsg("sitSound", function(msg)
local chair = retrieveStateObject("chair");
--chair.playSound("Stuhl setzen");
makeChairSound(chair, "Down");
end )
onMsg("act", function(msg)
doSomething();
sendDelayedMsgThis("act", 5000);
end )
onMsg("end", function(msg)
setCurrentPosition();
if testCancel() then
setState("standUp");
end
setState("waitForPartner");
end )
-- sit down on chair
state("sitDown")
onEnter(function(msg)
print("sitDown onEnter");
local chair = retrieveStateObject("chair");
if (not chair) then
print("playByTableChar::sitDown::onEnter: no chair");
exitStateMachine();
return
end
local boardgame = retrieveStateObject("boardgame");
if (not boardgame) then
print("playByTableChar::sitDown::onEnter: no boardgame");
exitStateMachine();
return
end
setPose("sitdownChair", retrieveData("mirrorAnims"));
chair.startAnimation("ChairSitdown");
chair.playSound("Stuhl hinsetzen");
-- send a delayed message for sit sound
sendDelayedMsgThis("sitSound", 2500);
end )
onMsg("sitSound", function(msg)
local chair = retrieveStateObject("chair");
--chair.playSound("Stuhl setzen");
makeChairSound(chair, "Down");
end )
onMsg("end", function(msg)
setCurrentPosition();
if testCancel() then
setState("standUp");
return
end
local partner = retrieveStateObject("partner");
if (not partner) then
print("no partner found");
return
end
sendMsg("partnerReady", partner);
setState("playSitting");
end )
state("waitForPartner")
onEnter(function(msg)
print("waitForPartner onEnter");
sendDelayedMsgThis("callPartner", 1000);
sendDelayedMsgThis("stopWaiting", 30000);
end )
onMsg("callPartner", function(msg)
print("callPartner");
if (testCancel()) then
sendMsgThis("stopWaiting");
return
end
-- get the game object server
local gameObjectServer = getParent().getGameObjectServer();
local partner = getOtherCharacter(getParent());
if (not partner or not isIdle(partner)) then
print("waitForPartner: no partner found");
getParent().setEmoticon(EMOTICON_NOPARTNER, EMOTICON_DELAY);
sendDelayedMsgThis("callPartner", 1000);
return
end
local table = retrieveStateObject("table");
local tableActionPointName = retrieveData("tableActionPointName");
local partnerChair = getOpposedChair(table, tableActionPointName);
if (not partnerChair) then
print("waitForPartner: no partner chair found");
partner.setEmoticon(EMOTICON_NOSEAT, EMOTICON_DELAY);
sendDelayedMsgThis("callPartner", 1000);
return
end
local chairActionPoint = partner.getClosestFreeActionPoint(partner, partnerChair, {"sit1", "sit2"});
if (not chairActionPoint) then
print("waitForPartner: partner chair in use TODO: check if partner allready sitting");
partner.setEmoticon(EMOTICON_CANNOT, EMOTICON_DELAY);
sendDelayedMsgThis("callPartner", 1000);
return
end
local wso = partner.walkSO;
storeStateObject("partner", wso);
if (not wso.walkToActionPoint(chairActionPoint)) then
print("waitForPartner: partner cant reach chair");
partner.setEmoticon(EMOTICON_NOPATH, EMOTICON_DELAY);
sendDelayedMsgThis("callPartner", 1000);
return
end
local boardgame = retrieveStateObject("boardgame");
-- create partners state machine contexts
local wsoContext = StateMachineContext();
wsoContext.storeStateObject("boardgame", boardgame);
wsoContext.storeStateObject("chair", partnerChair);
wsoContext.storeStateObject("partner", this);
wsoContext.storeData("chairActionPointName", chairActionPoint.getName());
wsoContext.storeData("activePart", false);
--this.storeData("activePart", true);
-- send partner to chair
wso.queueStateMachine("playByTableChar.sitDown", this, wsoContext);
end )
-- onMsg("end", function(msg)
-- if (testCancel()) then
-- local partner = retrieveStateObject("partner");
-- sendMsg("partnerStopped", partner);
-- setState("standUp");
-- else
-- if (getParent().isMale()) then
-- startAnimation("boardgameMike", retrieveData("mirrorAnims"));
-- else
-- startAnimation("boardgameElaine", retrieveData("mirrorAnims"));
-- end
-- end
-- end )
onMsg("partnerReady", function(msg)
local partner = retrieveStateObject("partner");
getParent().replaceQueueEntry(0, "pm_play");
partner.getParent().pushQueueEntry("pm_play");
setState("playSitting");
end )
onMsg("partnerStopped", function(msg)
setState("standUp");
end )
onMsg("stopWaiting", function(msg)
print("stopWaiting");
local partner = retrieveStateObject("partner");
if (partner) then sendMsg("partnerStopped", partner); end;
setState("standUp");
end )
onMsg("queue", function(msg)
local partner = retrieveStateObject("partner");
if (partner) then sendMsg("partnerStopped", partner); end;
setState("standUp");
end )
state("playSitting")
onEnter(function(msg)
print("playSitting onEnter");
if (getParent().isMale()) then
-- only sent for mike. elaine always has the first turn
sendDelayedMsgThis("startLoop", 12000);
else
sendMsgThis("startLoop");
end
local boardgame = retrieveStateObject("boardgame");
local playBoardgame = getParent().startActivity("playBoardgame", boardgame);
local length = getActivityLength(playBoardgame);
sendDelayedMsgThis("complete", length);
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end )
onMsg("startLoop", function(msg)
startAnimation(genderize(getParent(), "boardgame"), retrieveData("mirrorAnims"));
sendDelayedMsgThis("talk", 12000);
sendDelayedMsgThis("diceSound", 5600);
sendDelayedMsgThis("moveSound", 8000);
end )
onMsg("diceSound", function(msg)
getParent().playSound("gameDice");
end )
onMsg("moveSound", function(msg)
getParent().playSound("gameMove");
end )
onMsg("talk", function(msg)
print("talk in wso " .. getParent().getCharacterName());
sendMsg("talk", getParent().mimicSO);
sendDelayedMsgThis("talk", 24000);
end )
onMsg("partnerStopped", function(msg)
print("partnerStopped rec")
setState("standUp");
end )
onMsg("complete", function(msg)
local partner = retrieveStateObject("partner");
sendMsg("partnerStopped", partner);
setState("standUp");
end )
onMsg("testCancel", function(msg)
if testCancel() or (not this.getParent().getCurrentActivityGain()) then
sendMsgThis("complete");
else
sendDelayedMsgThis("testCancel", CANCEL_POLLING_INTERVAL);
end
end )
onMsg("end", function(msg)
if (testCancel()) then
sendMsgThis("complete");
else
sendMsgThis("startLoop");
end
end )
-- stand up from chair
state("standUp")
onEnter(function(msg)
print("standUp::onEnter");
startAnimation("standupChair", retrieveData("mirrorAnims"));
sendDelayedMsgThis("upSound", 900);
local chair = retrieveStateObject("chair");
chair.startAnimation("ChairSitdown", -1);
getParent().detachLeftObjectHolder();
getParent().detachRightObjectHolder();
local boardgame = retrieveStateObject("boardgame");
if (not boardgame) then
print("no boardgame to delete found")
else
getParent().stopAllActivities(boardgame);
--boardgame.deleteGameObject();
end
end )
onMsg("upSound", function(msg)
local chair = retrieveStateObject("chair");
makeChairSound(chair, "Up");
end )
onMsg("end", function(msg)
if (retrieveData("activePart")) then
local boardgame = retrieveStateObject("boardgame");
if (boardgame) then
boardgame.deleteGameObject();
end
end
setCurrentPosition();
exitAndGoAway();
end )
endStateMachine()